package com.ego.product.config;

import com.ego.product.interceptor.IndexInterceptor;
import com.ego.product.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: ego
 * @description: 实现请求直接映射页面
 * @author: KamTang
 * @create: 2022-12-12 11:44
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/cart/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/order/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/member/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/register").setViewName("register");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new IndexInterceptor()).addPathPatterns("/");
        registry.addInterceptor(new IndexInterceptor()).addPathPatterns("/cart/**");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/order/**");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/member/**");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/coupon/**");
    }
}
